//
//  CameraCollectionViewCell.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/14.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "CameraCollectionViewCell.h"
#import "LuBDefine.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation CameraCollectionViewCell

- (void)dealloc{
    [_avartarImageView release];
    [_photoImageView release];
    [_titleLabel release];
    [_bgImageView release];
    [super dealloc];
}

//初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createCameraCollectionViewCell];
    }
    return self;
}

//创建视图
- (void)createCameraCollectionViewCell{
    
    self.photoImageView = [[UIImageView alloc]init];
    [self addSubview:_photoImageView];
    [_photoImageView release];
    
    self.bgImageView = [[UIImageView alloc]init];
    self.bgImageView.backgroundColor = [UIColor blackColor];
    self.bgImageView.alpha = 0.6;
    [self.photoImageView addSubview:_bgImageView];
    [_bgImageView release];
    
    self.avartarImageView = [[UIImageView alloc]init];
    [self.bgImageView addSubview:_avartarImageView];
    [_avartarImageView release];
    
    self.titleLabel = [[UILabel alloc]init];
    [self.bgImageView addSubview:_titleLabel];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    [_titleLabel release];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.photoImageView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    self.bgImageView.frame = CGRectMake(0, HEIGHT - 34, WIDTH, 34);
    self.avartarImageView.frame = CGRectMake(2, 2, 30, 30);
    self.titleLabel.frame = CGRectMake(40,2, WIDTH - 35, 30);
}

- (void)setCamera:(Camera *)camera{
    if (_camera != camera) {
        [_camera release];
        _camera = [camera retain];
    }
    NSURL *phoImageViewUrl = [NSURL URLWithString:camera.photo];
    [self.photoImageView sd_setImageWithURL:phoImageViewUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];

    NSURL *avartarImageViewUrl = [NSURL URLWithString:camera.avartar];
    [self.avartarImageView sd_setImageWithURL:avartarImageViewUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    self.titleLabel.text = camera.title;
}

@end
